//
//  LTSignatureController.m
//  LTChat
//
//  Created by 俊松何 on 2017/7/28.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTSignatureController.h"

@interface LTSignatureController ()

@property(nonatomic,strong) UITextView *textView;
@end

@implementation LTSignatureController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
}

-(void)yd_addSubviews
{
    CGFloat offset = 0;
    if iSiPhoneX
    {
        offset = 20;
    }
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 74 + offset, WIDTH-10, 100)];
    _textView.backgroundColor = mainColor;
    _textView.textColor = [UIColor blackColor];
    _textView.font = [UIFont systemFontOfSize:15];
    _textView.text = [LTClient sharedClient].currentUser.signature;
    [self.view addSubview:_textView];
    [_textView becomeFirstResponder];

}

-(void)yd_layoutNavigation
{
    self.title = NSLTLocalizedString(@"personInfo.signature", nil);
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.size = CGSizeMake(44, 44);
    [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [but setTitle:NSLTLocalizedString(@"personInfo.signaturesave", nil) forState:UIControlStateNormal];
    [but addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    but.titleLabel.font = [UIFont systemFontOfSize:16];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:but];
    self.navigationItem.rightMargin = 5;
}

-(void)save{
    
    [MBProgressHUD showProcessHud:nil toView:self.view];
    NSDictionary *param = @{@"signature":self.textView.text};
    [[MTHttpTool shareTool] postPath:@"/user/update_info" parameters:param success:^(MTBaseData *datamodel) {
        [MBProgressHUD showSuccess:@"修改成功" toView:nil];
        [LTClient sharedClient].currentUser.signature = self.textView.text;
        MTUserModel *model = [MTUserModel currentUser];
        model.info.signature = self.textView.text;
        [MTUserModel saveCurrentUser:model];
        [[NSNotificationCenter defaultCenter] postNotificationName:UserInfoChange object:nil];
        [self.navigationController popViewControllerAnimated:YES];
    } failer:^(MTError *error) {
        [MBProgressHUD showError:error.errorDescription];
    }];
    
}

@end
